<template>
  <div>
    <nav-bar title="问答" />

    <div class="box">
      <div
        v-for="(item, i) in data"
        :key="i"
        class="content"
      >
        <div class="text">
          <div class="text-overflow">
            {{ item.title }}
          </div>
          <div class="down">
            赞同 {{ getCount(item.likeCount) }}&nbsp;
            评论 {{ getCount(item.commentCount) }}&nbsp;
            {{ moment(item.pubTimestamp).fromNow() }}
          </div>
        </div>
        <div class="photo">
          <img
            :src="item.thumbSrc"
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
export default {
  name: 'QaPage',
  data() {
    return {
      data: new Array(100)
        .fill(0)
        .map(() => ({
          // 标题
          title: '作为IT行业的过来人,你有什么话相对后辈说的？？？？？？？？？',
          // 点赞数 超过999显示为999+
          likeCount: 1234,
          // 评论数 超过999显示为999+
          commentCount: 555,
          // 发布时间
          pubTimestamp: 1658482134742,
          // 缩略图
          thumbSrc: 'https://pic1.zhimg.com/80/v2-8e77b2771314f674cccba5581560d333_xl.jpg?source=4e949a73',
        })),
    };
  },
  computed: {
    moment() {
      return moment
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    getCount(num) {
      return num > 999 ? '999+' : num;
    },
    // getTime(timestamp) {
    //   return moment(timestamp).fromNow();
    // },
  },
}
</script>

<style lang="less" scoped>

.top{
    margin-left: 30%;
    font-size: 20px;
}
.box{
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 95px);
  overflow: auto;
  /* outline: 1px solid black; */
  .content{
      border-bottom: 1px solid rgb(221, 221, 221);
      width: 100%;
      margin: 0px 0 ;
      padding: 20px 0;
      display: flex;
      flex-direction: row;
      border-bottom: 1px solid #eee;
    .text{
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      line-break: anywhere;
        .text-overflow{
          font-size:16px;
          overflow: hidden;
          -webkit-line-clamp: 2;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
        }
    }
  }
}
.down{
    margin-bottom: 8px;
    font-size: 12px;
    color: #999;
    margin-top: 10px;
}
.photo{
  height: 70px;
  margin-left: 10px;
  img {
    height: 100%;
    border-radius: 5px;
  }
}
</style>
